<link rel="stylesheet" type="text/css" href="../stylesheet/style.css"/>
<?php
/*
* @author Nguyen Xuan Hong
* @copyright 2011
*/

require_once('../includes/inform.tbl.php');

if($_GET['mode'] == 'listinform')
{
	$pClsInform = new clsInformTable();	
	if($pClsInform->avaibleSubmit()){
		$pClsInform->loadBuffer();
		$pClsInform->insertDB();
		echo acpredirect();
		exit();
	}
	echo $pClsInform->createForm('Thêm thông báo');
	
	require_once('../includes/templates.php');
	$table = new clsTable('lstinform',array(array("ID", "1"),array("Tiêu đề thông báo", 0),array("Sửa", 1),array("Xóa", 1)));
	$list_inform = $pClsInform->listobj(10);
	foreach($list_inform as $inform){
		$html_remove =      '<a href="?page=inform&mode=deleteinform&id='.$inform->value('id').'">Xóa</a>';
		$html_edit = 	'<a href="?page=inform&mode=editinform&id='.$inform->value('id').'">Sửa</a>';	
		$table->addRow($inform->value('id'),array($inform->value('id'),$inform->value('title'), $html_edit,$html_remove));
	}
	echo $table->putHTML(true);
	exit();
}

if($_GET['mode'] == 'deleteinform'){		
	// Redefine insert
	$deleteid = sget('id');			
	$pClsInform = new clsInformTable($deleteid);
	if(!$_POST['submit']){
		?>
        
	<center><div class="notification warning">
        <span></span>
        <p><strong>Warning!</strong> 
		<div class="text">Bạn có muốn xóa Thông báo này không</div> 
            <div class="btn"><form method='post'><input type='submit' name='submit' value = 'Xóa' /></form></div>
         </p>
	</div></center>
        <?
		exit();
	}
	$pClsInform->removeDB('id', $deleteid);
       header("location:index.php?page=inform&mode=listinform");
	exit();
}

if($_GET['mode'] == 'editinform')
{
	$edit = (int)sget('id');
	$pClsInform = new clsInformTable($deleteid);
	if($pClsInform->avaibleSubmit()){
		$pClsInform->loadBuffer();
		$pClsInform->updateDB('id',$edit);
        echo acpredirect('page=inform&mode=listinform');
		exit();
	}
	$pClsInform->loadDB('id',$edit);
       echo $pClsInform->createForm('Sửa thông báo');
	exit();
}
?> 
